package service;

import domain.Account;
import persistence.AccountDao;
import persistence.impl.AccountDaoImpl;

public class AccountService {
    private AccountDao accountDao;

    public AccountService(){
        this.accountDao = new AccountDaoImpl();
    }

//登录部分
    //根据用户名查询账户
    public Account getAccountByName(String username) {
        return accountDao.getAccountByUsername(username);
    }

    // 根据 username 和 password 从数据库获取一个 Account 对象。
    public Account getAccountByNameAndPassword(String username, String password) {
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        return accountDao.getAccountByUsernameAndPassword(username,password);
    }

//注册部分
    public void insertAccount(Account account) {
        accountDao.insertAccount(account);
        accountDao.insertProfile(account);
        accountDao.insertSignon(account);
    }

//修改账号部分
    public void updateAccount(Account account) {
        accountDao.updateAccount(account);
        accountDao.updateProfile(account);
        if (account.getPassword() != null && account.getPassword().length() > 0) {
            accountDao.updateSignon(account);
        }
    }

}
